// import key from 'keymaster';
export default {
    namespace: 'count',
    state: {
        record: 0,
        step: 1
    },
    subscriptions: {
        // keyboardWatcher({ dispatch }) {
        //     key('⌘+up, ctrl+up', () => { dispatch({ type: 'add' }) });
        // }
    },
    effects: {
        *addAsync(action, { call, put }) {
            yield call(delay, 1000);
            // put用来触发对应的reducer
            yield put({ type: 'add',data:10 });
        },
        *minusAsync(action,{call,put}){
            yield call(delay,1000);
            yield put({type:'minus',data:2});
        }
    },
    reducers: {
        add(state,action) {
            console.log(state,action);
            return {
                ...state,
                record: state.record+action.data
            };
        },
        minus(state,action) {
            console.log(state,'minus');
            return { ...state, record: state.record - action.data };
        }
    }
}

// 工具函数
function delay(timeout) {
    return new Promise(resolve => {
        setTimeout(resolve, timeout);
    });
}